﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/xing.js" type="text/javascript"></script>
<script type="text/javascript">
	$.jgrid.no_legacy_api = true;
	$.jgrid.useJSON = true;
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
var firstLoad = true;
var myStreets = [];
var udistrict, usid;

function searchCustomer() {
	var district = $("#sf_district").val();
	var sid = $("#sf_street").val();
	var commuid = $("#sf_community").val();
	var ctype = $("#sf_ctype").val();
	var cid   = $("#sf_cid").val();
	var idcard = $("#sf_idcard").val();
	var cname = $("#sf_cname").val();
	var cage  = $("#sf_cage").val();
	var q = "action=4&isquit=1&sf_district=" + district + "&sf_street=" + sid + "&sf_community=" + commuid + "&sf_ctype=" + ctype  
			+ "&sf_cid=<" + cid + ">&sf_idcard=<" + idcard + ">&sf_cname=" + escape(cname) + "&sf_cage>=" + cage;

	if (this.id == "sf_submit")
		jQuery("#list1").jqGrid('setGridParam',{page:1,url:"main?" + q}).trigger("reloadGrid");
	else
		$("#df").attr("src","main?oper=excel&" + q); 
}

function sfDistrictChange() {
	if (usid != "0") {
		$("#sf_district").val(udistrict);
		$("#sf_street").html("<option value='0'>全  部</option>" + initStreet(udistrict));
		sfStreetChange();
		return;
	}
	
	var district = $("#sf_district").val();
	
	if (district == "0") {
		$("#sf_street").html("<option value='0'>选择街道</option>");
	} else {
		$("#sf_street").html("<option value='0'>全  部</option>" + initStreet(district));
		$("#sf_street").val("0");
	}
	$("#sf_community").html("<option value='0'>选择社区</option>");
}

function sfStreetChange() {
	if (usid != "0") {
		$("#sf_street").val(usid);
	}
	
	var sid = $("#sf_street").val();
	
	if ((sid == null) || (sid.length == 1)) {
		$("#sf_community").html("<option value='0'>选择社区</option>");
	} else {
		$("#sf_community").html("<option value='0'>全  部</option>" + initCommunity(sid));
	}
}

function loadStreetCommunity() {
	$.get('base?action=12',function (data, textStatus){
		$.extend(true, myStreets, data);
	});
}

function initStreet(district) {
	var ops = "";
	for (i = 0; i < myStreets.length; i++) {
		if (myStreets[i].district != district)
			continue;
		ops += "<option value='" + myStreets[i].sid + "'>" + myStreets[i].sid + "|" + myStreets[i].sname + "</option>";
	}
	return ops;
}

function initCommunity(sid) {
	var ops = "";
	for (var i = 0; i < myStreets.length; i++) {
		if (myStreets[i].sid != sid) 
			continue;
		var cs = myStreets[i].communitys;
		
		for (var j = 0; j < cs.length; j++) {
			ops += "<option value='" + cs[j].cid + "'>" + cs[j].cid + "|" + cs[j].cname + "</option>";
		}
	}

	//$("#commuid").html(ops);
	return ops;
}

function setGridButton() {
	if ((!firstLoad) || (udistrict == "0"))
		return;
	
	jQuery("#list1").jqGrid('navGrid','#gridpager1',{edit:false,add:false,del:false,refresh:false,search:false})
	.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"重新加入", 
   		buttonicon:"ui-icon-plus", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				var cname = jQuery("#list1").jqGrid('getCell', gr, 1);
				if( gr != null )
				  jQuery("#list1").jqGrid('delGridRow', gr, {
				  				caption:"确定要重新加入这个已退出人员吗?", 
				  				msg:"该已退出人员姓名为：'" + cname + "'",
				  				bSubmit:"加入",
				  				delicon: [true,'left','ui-icon-plus'],
				  				delData: ['restore'],
				  				top: 200,
				  				left: 400,
				  				modal: true,
				  				closeAfterEdit:true, 
				  				reloadAfterSubmit:true,
				  				afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					if (data.code != 1)
				  						return [false, "操作失败！"];
				  					else
				  						return [true, "操作成功！"];
				  				}
				  			});
				else
					showTips("请选择要重新加入的已退出人员");
			}
		})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"删除", 
   		buttonicon:"ui-icon-close", 
   		onClickButton: function(){
				var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
				var cname = jQuery("#list1").jqGrid('getCell', gr, 1);
				if( gr != null )
				  jQuery("#list1").jqGrid('delGridRow', gr, {
				  				caption:"确定要删除这个已退出人员吗?", 
				  				msg:"该已退出人员姓名为：'" + cname + "'",
				  				bSubmit:"删除",
				  				delData: ['death'],
				  				top: 200,
				  				left: 400,
				  				modal: true,
				  				closeAfterEdit:true, 
				  				reloadAfterSubmit:true,
				  				afterSubmit : function(r, postdata) {
				  					var data = eval('(' + r.responseText + ')');
				  					if (data.code != 1)
				  						return [false, "删除失败！"];
				  					else
				  						return [true, "删除成功！"];
				  				}
				  			});
				else
					showTips("请选择要删除的已退出人员");
			}
		});
	firstLoad = false;
}

function setGrid() {
	jQuery("#list1").jqGrid({ 
			url:'main?action=4&isquit=1',
			hidegrid: "false",
			datatype: "json",
			colNames:['客户编号','姓名','性别','民族','类别','身份证号','家庭人数','住址','户口所在地','所属区','所属街道','所属社区','身体状况','账户余额','每月应冲值','服务次数','手机号码','固定电话','退出日期'],
			colModel:[ 
					{name:'cid', width:100, sortable:false, align:'right'}, 
					{name:'cname', width:40, sortable:false, align:'right'},
					{name:'csex',width:30, sortable:false, align:'right', formatter:'select', editoptions:{value:"F:女;M:男"}},
					{name:'nationality', width:30, sortable:false, align:'right'},
					{name:'ctype',width:60, sortable:false, align:'right', formatter:'select', editoptions:{value:"1:三无老人;2:70岁低保;3:85岁高龄;4:70岁优抚;5:70岁劳模"}},
					{name:'idcard', width:120, sortable:false, align:'right'},
					{name:'family', width:60, sortable:false, align:'right'},
					{name:'caddress',width:160, sortable:false, align:'right'},
					{name:'residence', width:160, sortable:false, align:'right'},
					{name:'district',width:50, sortable:false, align:'right', formatter:'select', editoptions:{value:"1:市辖区;2:桥东区;3:桥西区;4:高新区;5:宣化区;6:下花园区"}},
					{name:'sid', width:50, sortable:false, align:'right', hidden:true},
					{name:'commuid', width:80, sortable:false, align:'right', hidden:true},
					{name:'health', width:60, sortable:false, align:'right'},
					{name:'cursum', width:50, sortable:false, align:'right'},
					{name:'subsidy', width:70, sortable:false, align:'right'},
					{name:'servnum', width:70, sortable:false, align:'right'},
					{name:'cmobile', width:70, sortable:false, align:'right'},
					{name:'ctel', width:70, sortable:false, align:'right'},
					{name:'shiftdate', width:70, sortable:false, align:'right'}
			], 
			viewrecords: true,
			rowNum:20,
			pager: '#gridpager1',
			height: 460,
			editurl:'main?action=22&isquit=1',
			caption:"退出三无低保人员信息",
			gridComplete: function() {
				udistrict = jQuery("#list1").jqGrid('getGridParam', 'userData')["udistrict"];
				usid = jQuery("#list1").jqGrid('getGridParam', 'userData')["usid"];
				setGridButton();
				if (usid != "0") {
					$("#sf_district").val(udistrict);
					sfDistrictChange();
				}
			}
	})}; 
	
	$(document).ready(function(){
		loadStreetCommunity();
		setGrid();
		$("#sf_submit").click(searchCustomer);
		$("#sf_excel").click(searchCustomer);
		$("#sf_street").live('change', sfStreetChange);
	});
</script>

<body style="background-color:#4e84c0;">
						<iframe id="df"  name="df" src="" width=0 height=0 frameborder="0" ></iframe>
						<form id="sf" action="main">
                	<table>
	                	<tr>
		                	<td>选择所属区</td>
		                	<td><select id="sf_district" name="sf_district" onChange="sfDistrictChange()">
			                		<option value="0" selected>全  市</option>
			                		<option value="1">市辖区</option>
			                		<option value="2">桥东区</option>
			                		<option value="3">桥西区</option>
			                		<option value="4">高新区</option>
			                		<option value="5">宣化区</option>
			                		<option value="6">下花园区</option>
			                	</select></td>
		                	<td>  街道办事处 </td>
		                	<td><select id="sf_street" name="sf_street">
		                								<option value='0'>选择街道</option>
		                						 </select></td>
		                	<td>  编号(*)</td>
		                	<td><input type="text" id="sf_cid" name="sf_cid" size="22" maxlength="13"/></td>
		                	<td>  姓名</td>
		                	<td><input type="text" id="sf_cname" name="sf_cname" size="10" maxlength="4"/></td>
		                	<td><input type="button" id="sf_submit" value="查 询"></td>
				            </tr>
				          	<tr>
				          		<td>居委会</td>
		                	<td><select id="sf_community" name="sf_community"/>
		                						<option value='0'>选择社区</option>
		                				 </select></td>
		                	<td>  人员类型</td>
		                	<td><select id="sf_ctype" name="sf_ctype">
				                		<option value="0">全  部</option>
				                		<option value="1">三无老人</option>
				                		<option value="2">70岁低保</option>
				                		<option value="3">85岁高龄</option>
				                		<option value="4">70岁优抚</option>
			                			<option value="5">70岁劳模</option>
				                	</select></td>
		                	<td>身份证(*)</td>
		                	<td><input type="text" id="sf_idcard" name="sf_idcard" size="22" maxlength="18"/></td>
		                	
		                	<td>年龄</td>
		                	<td><input type="text" id="sf_cage" name="sf_cage" size="8" maxlength="2"/></td>
		                	<td><input type="button" id="sf_excel" value="导 出"></td>
	                	</tr>
                	</table>
                	</form>
				<div id="RightPane"  >
					<div class="innertube">
					<table id="list1"></table>
					<div id="gridpager1"></div>
				</div>
				</div>

</body>
